package com.common.www.service.tabulation;


import org.springframework.boot.base.jpa.service.BaseLogicService;
import com.common.www.bean.entity.project.BiddingCompany;
import com.common.www.bean.entity.project.Project;
import com.common.www.bean.entity.tabulation.InnerSummary;
import com.common.www.repository.tabulation.InnerSummaryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;


@Service
@Transactional
public class InnerSummaryService extends BaseLogicService<InnerSummary,Long> {
    @Autowired
    private InnerSummaryRepository repository;
    @Override
    public InnerSummaryRepository getRepository() {
        return repository;
    }


    /**
     * 标底：生成清单关联基础信息
     * @param project
     * @param jieDuan
     */
    public void saveCorrelationBd(Project project, Integer jieDuan,String fileName){
        InnerSummary innerSummarie = null;
        if (jieDuan == 1){
            innerSummarie = getRepository().getByConditionJieDuanOne(project.getId());
        }else if (jieDuan == 2){
            innerSummarie = getRepository().getByConditionJieDuanSeven(project.getId());
        }
        if (innerSummarie == null){
            innerSummarie = new InnerSummary();
            innerSummarie.setProject(project);
            innerSummarie.setJieDuan(jieDuan);
            innerSummarie.setLoadDf(0.0);
            innerSummarie.setFileName(fileName);
        }
        repository.save(innerSummarie);
    }


    /**
     * 供应商清单：生成清单关联基础信息
     * @param biddingCompany
     * @param jieDuan
     * @param fileName
     */
    public void saveCorrelationGys(BiddingCompany biddingCompany, Integer jieDuan,String fileName){
        InnerSummary innerSummarie = null;
        if (jieDuan != 1 && jieDuan != 2){
            innerSummarie = repository.getByConditionJieDuanTemp(biddingCompany.getProject().getId(),biddingCompany.getId(),jieDuan);
        }
        if (innerSummarie == null){
            innerSummarie = new InnerSummary();
            innerSummarie.setProject(biddingCompany.getProject());
            innerSummarie.setBiddingCompany(biddingCompany);
            innerSummarie.setJieDuan(jieDuan);
            innerSummarie.setLoadDf(0.0);
            innerSummarie.setFileName(fileName);
        }
        repository.save(innerSummarie);
    }

}
